<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>生活服务上架</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
          <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
          <link rel="stylesheet" href="${pageContext.request.contextPath}/static/plugins/jquery.time/jquery.timepicker.min.css">
    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"
        type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/jquery.time/jquery.timepicker.min.js"
        type="text/javascript"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/js/jquery.form.js" type="text/javascript"></script>
	<style >
		.jqGrid_wrapper{*+margin-left:270px;}
	
		.lt{float:left}
		.form-group{*+overflow:hidden;}
		.form-group label{width:28%\9;*+width:20%;text-align:right\9;*+text-align:right;}
		.col-sm-8 .m-t2 {width:22%\9;}
		.form-group .col-sm-8{width:66%\9;*+width:66%;}
		.form-group .form-control{*+width:95%;}
		.form-control{*+height:30px;}
	</style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
    <div class="jqGrid_wrapper">
        <div id="jqGrid_operation" class="jg-grid">
            <h1>新增生活服务资源</h1>
            <div class="jqGrid_operation" id="action"></div>
        </div>

        <div class="col-sm-12">
		    <form class="form-horizontal m-t" method="post" id="form">
		        <input type="hidden" name="content" id="content" />
		        <div class="form-group">
		            <label class="col-sm-3 control-label lt"><i class="require">*</i>名称:</label>
		            <div class="col-sm-8 lt">
		                <input class="form-control" name="cName" id="cName" size="30"/>
		            </div>
		        </div>
		        
		        <div class="form-group">
		            <label class="col-sm-3 col-sm-3 control-label lt"><i class="require">*</i>图标:</label>
		            <div class="col-sm-8 lt">
		                <div class="input-group">
		                    <a class="btn btn-primary" onclick="picCut()" style="*+width:14%;">上传图片并裁剪</a>
		                </div>
		            </div>
		        </div>
		         <div class="form-group">
		            <label class="col-sm-3 control-label lt"><i class="require">*</i>资源是否共享:</label>
		            <div class="col-sm-8">
		                <div class="col-sm-2 m-t2 lt">
		                    <input type="radio" checked name="ifShare" size="30" value="1"/><label>共享</label>
		                </div>
		                <div class="col-sm-2 m-t2 lt">
		                    <input type="radio" name="ifShare" size="30" value="0"/ class="lt"><label style="*+width:28%;float:left;">不共享</label>
		                </div>
		            </div>
		        </div>
		        <div class="form-group">
		            <label class="col-sm-3 control-label lt"><i class="require">*</i>排序（APP）:</label>
		            <div class="col-sm-8 lt">
		                <select name="sort" id="sort" class="select2">
		                    <option value="1">1</option>
		                    <option value="2">2</option>
		                    <option value="3">3</option>
		                    <option value="4">4</option>
		                    <option value="5">5</option>
		                    <option value="6">6</option>
		                    <option value="7">7</option>
		                    <option value="8">8</option>
		                    <option value="9">9</option>
		                </select>
		            </div>
		        </div>
		        <div class="form-group">
		            <label class="col-sm-3 col-sm-3 control-label lt"><i class="require">*</i>跳转URL:</label>
		            <div class="col-sm-8 lt">
		                <input class="form-control" name="cUrl" id="cUrl" size="30"/>
		            </div>
		        </div>
		         <div class="form-group">
		            <label class="col-sm-3 col-sm-3 control-label lt">结算方式:</label>
		            <div class="col-sm-8 lt">
		                <input class="form-control" name="settlementMethod" size="30"/>
		            </div>
		        </div>
		        <div class="form-group">
		            <label class="col-sm-3 col-sm-3 control-label lt">预计收益:</label>
		            <div class="col-sm-8 lt">
		                <input class="form-control" name="expectedIncome" size="30"/>
		            </div>
		        </div>
		        <div class="form-group">
		            <label class="col-sm-3 col-sm-3 control-label lt">广告详情:</label>
		            <div class="col-sm-8 lt">
		                <input class="form-control" name="adDetails" size="30"/>
		            </div>
		        </div>
		        <div class="form-group">
		            <label class="col-sm-3 col-sm-3 control-label lt">上架人:</label>
		            <div class="col-sm-8 lt">
		            	<input class="form-control" name="operator" size="30" value="${sessionScope.user.uname}" disabled="disabled"/>
		            </div>
		        </div>
		        <div class="form-group">
		            <label class="col-sm-3 col-sm-3 control-label lt">上架时间:</label>
		            <div class="col-sm-8 lt">
		            	<input class="form-control" name="cTime" size="30" id="cTime" disabled="disabled"/>
		            </div>
		        </div>
		    </form>
		</div>
		<div style="text-align: center;">
         <button class="btn btn-success form-control" id="sub" onclick="checkTail()" style="width: 150px;">提交</button>
         <button class="btn btn-success form-control" id="cancel" onclick="cancel()" style="width: 150px;">取消</button>
     	</div>
    </div>
</div>

<script>
    $(function () {
    	var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
    	$("#cTime").val(currentdate);
        $(".select2").select2({
            minimumResultsForSearch: -1,
            width:'100%'
        });

       
    });
    function picCut(){
    	layer.open({
            type: 2,
            title: ['图片裁剪', 'font-weight:bold'],
            shadeClose: true, //点击遮罩关闭层
            scrollbar: false,
            area: ['1000px', '650px'],
            content: '${pageContext.request.contextPath}/admin/lifeResource_picView.action?path=lifeResource',
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var options = {
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.code == 1) {
               				$("#content").val(data.content);
                            layer.alert(data.msg);
                            layer.close(index);
                        } else {
                            layer.alert(data.msg);
                        }
                    }
                };
				 $("#layui-layer-iframe" + index).contents().find("#getData").click();
				 $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
	                $("#layui-layer-iframe" + index).contents().find("#form").submit();
// 				 $("#layui-layer-iframe" + index).contents().find("#sure").click(); 
            },
            cancel: function (index) {
                layer.close(index);
            }
        });
    }
    function checkTail(){
		$("#sub").attr("disabled", "true");
		var cName = $("#cName").val();
	    var cUrl = $("#cUrl").val();
	    var content = $("#content").val();
	    var formData = new FormData($("#form" )[0]); 
	    if(!cName){
	    	 alert("资源名称必填");
	    	 $("#sub").removeAttr("disabled");
	    	 return;
	    }
	    if(!content){
	    	 alert("请选择图片并截图上传");
	    	 $("#sub").removeAttr("disabled");
	    	 return;
	    }
        if(!cUrl){
           	var reg =new RegExp("^((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?$"); 
           	if(!reg.test(cUrl)){
	           	alert("url格式错误,请输入http: 或 https:开头");
		    	$("#sub").removeAttr("disabled");
		    	return;	
           	}
        }
        
        $.ajax({  
            url: '${pageContext.request.contextPath}/admin/lifeResource_add.action' ,  
            type: 'POST',  
            data: formData,  
            async: false,  
            cache: false,  
            contentType: false,  
            processData: false,  
            success: function (result) {  
                 result = JSON.parse(result)
                 if (result.code == 1) {
                	 layer.alert(result.msg);
                	 window.location.href = "${pageContext.request.contextPath}/admin/lifeResource_listView.action";
                 }else{
                	 $("#sub").removeAttr("disabled");
                 	layer.alert(result.msg);
                 }
            },  
            error: function (returndata) {  
                alert(returndata);  
            }  
       }); 
	    
	}
    function cancel(){
    	window.location.href = "${pageContext.request.contextPath}/admin/lifeResource_listView.action";
    }
</script>
</body>
</html>
